<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>seamlessfield_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_editor_seamlessfield_test.js.html">seamlessfield_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Trogedit unit tests for goog.editor.SeamlessField.
<a name="line17"></a> *
<a name="line18"></a> * @author nicksantos@google.com (Nick Santos)
<a name="line19"></a> * @suppress {missingProperties} There are many mocks in this unit test,
<a name="line20"></a> *     and the mocks don&#39;t fit well in the type system.
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.editor.seamlessfield_test&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.dom&#39;);
<a name="line26"></a>goog.require(&#39;goog.dom.DomHelper&#39;);
<a name="line27"></a>goog.require(&#39;goog.dom.Range&#39;);
<a name="line28"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line29"></a>goog.require(&#39;goog.editor.Field&#39;);
<a name="line30"></a>goog.require(&#39;goog.editor.SeamlessField&#39;);
<a name="line31"></a>goog.require(&#39;goog.events&#39;);
<a name="line32"></a>goog.require(&#39;goog.functions&#39;);
<a name="line33"></a>goog.require(&#39;goog.style&#39;);
<a name="line34"></a>goog.require(&#39;goog.testing.MockClock&#39;);
<a name="line35"></a>goog.require(&#39;goog.testing.MockRange&#39;);
<a name="line36"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line37"></a>
<a name="line38"></a>goog.setTestOnly(&#39;seamlessfield_test&#39;);
<a name="line39"></a>
<a name="line40"></a>var fieldElem;
<a name="line41"></a>var fieldElemClone;
<a name="line42"></a>
<a name="line43"></a>function setUp() {
<a name="line44"></a>  fieldElem = goog.dom.getElement(&#39;field&#39;);
<a name="line45"></a>  fieldElemClone = fieldElem.cloneNode(true);
<a name="line46"></a>}
<a name="line47"></a>
<a name="line48"></a>function tearDown() {
<a name="line49"></a>  goog.events.removeAll();
<a name="line50"></a>  fieldElem.parentNode.replaceChild(fieldElemClone, fieldElem);
<a name="line51"></a>}
<a name="line52"></a>
<a name="line53"></a>// the following tests check for blended iframe positioning. They really
<a name="line54"></a>// only make sense on browsers without contentEditable.
<a name="line55"></a>function testBlankField() {
<a name="line56"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line57"></a>    assertAttachSeamlessIframeSizesCorrectly(
<a name="line58"></a>        initSeamlessField(&#39;&amp;nbsp;&#39;, {}), createSeamlessIframe());
<a name="line59"></a>  }
<a name="line60"></a>}
<a name="line61"></a>
<a name="line62"></a>function testFieldWithContent() {
<a name="line63"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line64"></a>    assertAttachSeamlessIframeSizesCorrectly(
<a name="line65"></a>        initSeamlessField(&#39;Hi!&#39;, {}), createSeamlessIframe());
<a name="line66"></a>  }
<a name="line67"></a>}
<a name="line68"></a>
<a name="line69"></a>function testFieldWithPadding() {
<a name="line70"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line71"></a>    assertAttachSeamlessIframeSizesCorrectly(
<a name="line72"></a>        initSeamlessField(&#39;Hi!&#39;, {&#39;padding&#39;: &#39;2px 5px&#39;}),
<a name="line73"></a>        createSeamlessIframe());
<a name="line74"></a>  }
<a name="line75"></a>}
<a name="line76"></a>
<a name="line77"></a>function testFieldWithMargin() {
<a name="line78"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line79"></a>    assertAttachSeamlessIframeSizesCorrectly(
<a name="line80"></a>        initSeamlessField(&#39;Hi!&#39;, {&#39;margin&#39;: &#39;2px 5px&#39;}),
<a name="line81"></a>        createSeamlessIframe());
<a name="line82"></a>  }
<a name="line83"></a>}
<a name="line84"></a>
<a name="line85"></a>function testFieldWithBorder() {
<a name="line86"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line87"></a>    assertAttachSeamlessIframeSizesCorrectly(
<a name="line88"></a>        initSeamlessField(&#39;Hi!&#39;, {&#39;border&#39;: &#39;2px 5px&#39;}),
<a name="line89"></a>        createSeamlessIframe());
<a name="line90"></a>  }
<a name="line91"></a>}
<a name="line92"></a>
<a name="line93"></a>function testFieldWithOverflow() {
<a name="line94"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line95"></a>    assertAttachSeamlessIframeSizesCorrectly(
<a name="line96"></a>        initSeamlessField([&#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;].join(&#39;&lt;p/&gt;&#39;),
<a name="line97"></a>        {&#39;overflow&#39;: &#39;auto&#39;, &#39;position&#39;: &#39;relative&#39;, &#39;height&#39;: &#39;20px&#39;}),
<a name="line98"></a>        createSeamlessIframe());
<a name="line99"></a>    assertEquals(20, fieldElem.offsetHeight);
<a name="line100"></a>  }
<a name="line101"></a>}
<a name="line102"></a>
<a name="line103"></a>function testFieldWithOverflowAndPadding() {
<a name="line104"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line105"></a>    var blendedField = initSeamlessField(
<a name="line106"></a>        [&#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;].join(&#39;&lt;p/&gt;&#39;),
<a name="line107"></a>        {
<a name="line108"></a>          &#39;overflow&#39;: &#39;auto&#39;,
<a name="line109"></a>          &#39;position&#39;: &#39;relative&#39;,
<a name="line110"></a>          &#39;height&#39;: &#39;20px&#39;,
<a name="line111"></a>          &#39;padding&#39;: &#39;2px 3px&#39;
<a name="line112"></a>        });
<a name="line113"></a>    var blendedIframe = createSeamlessIframe();
<a name="line114"></a>    assertAttachSeamlessIframeSizesCorrectly(blendedField, blendedIframe);
<a name="line115"></a>    assertEquals(24, fieldElem.offsetHeight);
<a name="line116"></a>  }
<a name="line117"></a>}
<a name="line118"></a>
<a name="line119"></a>function testIframeHeightGrowsOnWrap() {
<a name="line120"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line121"></a>    var clock = new goog.testing.MockClock(true);
<a name="line122"></a>    var blendedField;
<a name="line123"></a>    try {
<a name="line124"></a>      blendedField = initSeamlessField(&#39;&#39;,
<a name="line125"></a>          {&#39;border&#39;: &#39;1px solid black&#39;, &#39;height&#39;: &#39;20px&#39;});
<a name="line126"></a>      blendedField.makeEditable();
<a name="line127"></a>      blendedField.setHtml(false, &#39;Content that should wrap after resize.&#39;);
<a name="line128"></a>
<a name="line129"></a>      // Ensure that the field was fully loaded and sized before measuring.
<a name="line130"></a>      clock.tick(1);
<a name="line131"></a>
<a name="line132"></a>      // Capture starting heights.
<a name="line133"></a>      var unwrappedIframeHeight = blendedField.getEditableIframe().offsetHeight;
<a name="line134"></a>
<a name="line135"></a>      // Resize the field such that the text should wrap.
<a name="line136"></a>      fieldElem.style.width = &#39;200px&#39;;
<a name="line137"></a>      blendedField.doFieldSizingGecko();
<a name="line138"></a>
<a name="line139"></a>      // Iframe should grow as a result.
<a name="line140"></a>      var wrappedIframeHeight = blendedField.getEditableIframe().offsetHeight;
<a name="line141"></a>      assertTrue(&#39;Wrapped text should cause iframe to grow - initial height: &#39; +
<a name="line142"></a>          unwrappedIframeHeight + &#39;, wrapped height: &#39; + wrappedIframeHeight,
<a name="line143"></a>          wrappedIframeHeight &gt; unwrappedIframeHeight);
<a name="line144"></a>    } finally {
<a name="line145"></a>      blendedField.dispose();
<a name="line146"></a>      clock.dispose();
<a name="line147"></a>    }
<a name="line148"></a>  }
<a name="line149"></a>}
<a name="line150"></a>
<a name="line151"></a>function testDispatchIframeResizedForWrapperHeight() {
<a name="line152"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line153"></a>    var clock = new goog.testing.MockClock(true);
<a name="line154"></a>    var blendedField = initSeamlessField(&#39;Hi!&#39;, {&#39;border&#39;: &#39;2px 5px&#39;});
<a name="line155"></a>    var iframe = createSeamlessIframe();
<a name="line156"></a>    blendedField.attachIframe(iframe);
<a name="line157"></a>
<a name="line158"></a>    var resizeCalled = false;
<a name="line159"></a>    goog.events.listenOnce(
<a name="line160"></a>        blendedField,
<a name="line161"></a>        goog.editor.Field.EventType.IFRAME_RESIZED,
<a name="line162"></a>        function() {
<a name="line163"></a>          resizeCalled = true;
<a name="line164"></a>        });
<a name="line165"></a>
<a name="line166"></a>    try {
<a name="line167"></a>      blendedField.makeEditable();
<a name="line168"></a>      blendedField.setHtml(false, &#39;Content that should wrap after resize.&#39;);
<a name="line169"></a>
<a name="line170"></a>      // Ensure that the field was fully loaded and sized before measuring.
<a name="line171"></a>      clock.tick(1);
<a name="line172"></a>
<a name="line173"></a>      assertFalse(&#39;Iframe resize must not be dispatched yet&#39;, resizeCalled);
<a name="line174"></a>
<a name="line175"></a>      // Resize the field such that the text should wrap.
<a name="line176"></a>      fieldElem.style.width = &#39;200px&#39;;
<a name="line177"></a>      blendedField.sizeIframeToWrapperGecko_();
<a name="line178"></a>      assertTrue(&#39;Iframe resize must be dispatched for Wrapper&#39;, resizeCalled);
<a name="line179"></a>    } finally {
<a name="line180"></a>      blendedField.dispose();
<a name="line181"></a>      clock.dispose();
<a name="line182"></a>    }
<a name="line183"></a>  }
<a name="line184"></a>}
<a name="line185"></a>
<a name="line186"></a>function testDispatchIframeResizedForBodyHeight() {
<a name="line187"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line188"></a>    var clock = new goog.testing.MockClock(true);
<a name="line189"></a>    var blendedField = initSeamlessField(&#39;Hi!&#39;, {&#39;border&#39;: &#39;2px 5px&#39;});
<a name="line190"></a>    var iframe = createSeamlessIframe();
<a name="line191"></a>    blendedField.attachIframe(iframe);
<a name="line192"></a>
<a name="line193"></a>    var resizeCalled = false;
<a name="line194"></a>    goog.events.listenOnce(
<a name="line195"></a>        blendedField,
<a name="line196"></a>        goog.editor.Field.EventType.IFRAME_RESIZED,
<a name="line197"></a>        function() {
<a name="line198"></a>          resizeCalled = true;
<a name="line199"></a>        });
<a name="line200"></a>
<a name="line201"></a>    try {
<a name="line202"></a>      blendedField.makeEditable();
<a name="line203"></a>      blendedField.setHtml(false, &#39;Content that should wrap after resize.&#39;);
<a name="line204"></a>
<a name="line205"></a>      // Ensure that the field was fully loaded and sized before measuring.
<a name="line206"></a>      clock.tick(1);
<a name="line207"></a>
<a name="line208"></a>      assertFalse(&#39;Iframe resize must not be dispatched yet&#39;, resizeCalled);
<a name="line209"></a>
<a name="line210"></a>      // Resize the field to a different body height.
<a name="line211"></a>      var bodyHeight = blendedField.getIframeBodyHeightGecko_();
<a name="line212"></a>      blendedField.getIframeBodyHeightGecko_ = function() {
<a name="line213"></a>        return bodyHeight + 1;
<a name="line214"></a>      };
<a name="line215"></a>      blendedField.sizeIframeToBodyHeightGecko_();
<a name="line216"></a>      assertTrue(&#39;Iframe resize must be dispatched for Body&#39;, resizeCalled);
<a name="line217"></a>    } finally {
<a name="line218"></a>      blendedField.dispose();
<a name="line219"></a>      clock.dispose();
<a name="line220"></a>    }
<a name="line221"></a>  }
<a name="line222"></a>}
<a name="line223"></a>
<a name="line224"></a>function testDispatchBlur() {
<a name="line225"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE &amp;&amp;
<a name="line226"></a>      !goog.editor.BrowserFeature.CLEARS_SELECTION_WHEN_FOCUS_LEAVES) {
<a name="line227"></a>    var blendedField = initSeamlessField(&#39;Hi!&#39;, {&#39;border&#39;: &#39;2px 5px&#39;});
<a name="line228"></a>    var iframe = createSeamlessIframe();
<a name="line229"></a>    blendedField.attachIframe(iframe);
<a name="line230"></a>
<a name="line231"></a>    var blurCalled = false;
<a name="line232"></a>    goog.events.listenOnce(blendedField, goog.editor.Field.EventType.BLUR,
<a name="line233"></a>        function() {
<a name="line234"></a>          blurCalled = true;
<a name="line235"></a>        });
<a name="line236"></a>
<a name="line237"></a>    var clearSelection = goog.dom.Range.clearSelection;
<a name="line238"></a>    var cleared = false;
<a name="line239"></a>    var clearedWindow;
<a name="line240"></a>    blendedField.editableDomHelper = new goog.dom.DomHelper();
<a name="line241"></a>    blendedField.editableDomHelper.getWindow =
<a name="line242"></a>        goog.functions.constant(iframe.contentWindow);
<a name="line243"></a>    var mockRange = new goog.testing.MockRange();
<a name="line244"></a>    blendedField.getRange = function() {
<a name="line245"></a>      return mockRange;
<a name="line246"></a>    };
<a name="line247"></a>    goog.dom.Range.clearSelection = function(opt_window) {
<a name="line248"></a>      clearSelection(opt_window);
<a name="line249"></a>      cleared = true;
<a name="line250"></a>      clearedWindow = opt_window;
<a name="line251"></a>    }
<a name="line252"></a>    var clock = new goog.testing.MockClock(true);
<a name="line253"></a>
<a name="line254"></a>    mockRange.collapse(true);
<a name="line255"></a>    mockRange.select();
<a name="line256"></a>    mockRange.$replay();
<a name="line257"></a>    blendedField.dispatchBlur();
<a name="line258"></a>    clock.tick(1);
<a name="line259"></a>
<a name="line260"></a>    assertTrue(&#39;Blur must be dispatched.&#39;, blurCalled);
<a name="line261"></a>    assertTrue(&#39;Selection must be cleared.&#39;, cleared);
<a name="line262"></a>    assertEquals(&#39;Selection must be cleared in iframe&#39;,
<a name="line263"></a>        iframe.contentWindow, clearedWindow);
<a name="line264"></a>    mockRange.$verify();
<a name="line265"></a>    clock.dispose();
<a name="line266"></a>  }
<a name="line267"></a>}
<a name="line268"></a>
<a name="line269"></a>function testSetMinHeight() {
<a name="line270"></a>  if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line271"></a>    var clock = new goog.testing.MockClock(true);
<a name="line272"></a>    try {
<a name="line273"></a>      var field = initSeamlessField(
<a name="line274"></a>          [&#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;].join(&#39;&lt;p/&gt;&#39;),
<a name="line275"></a>          {&#39;position&#39;: &#39;relative&#39;, &#39;height&#39;: &#39;60px&#39;});
<a name="line276"></a>
<a name="line277"></a>      // Initially create and size iframe.
<a name="line278"></a>      var iframe = createSeamlessIframe();
<a name="line279"></a>      field.attachIframe(iframe);
<a name="line280"></a>      field.iframeFieldLoadHandler(iframe, &#39;&#39;, {});
<a name="line281"></a>      // Need to process timeouts set by load handlers.
<a name="line282"></a>      clock.tick(1000);
<a name="line283"></a>
<a name="line284"></a>      var normalHeight = goog.style.getSize(iframe).height;
<a name="line285"></a>
<a name="line286"></a>      var delayedChangeCalled = false;
<a name="line287"></a>      goog.events.listen(field, goog.editor.Field.EventType.DELAYEDCHANGE,
<a name="line288"></a>          function() {
<a name="line289"></a>            delayedChangeCalled = true;
<a name="line290"></a>          });
<a name="line291"></a>
<a name="line292"></a>      // Test that min height is obeyed.
<a name="line293"></a>      field.setMinHeight(30);
<a name="line294"></a>      clock.tick(1000);
<a name="line295"></a>      assertEquals(&#39;Iframe height must match min height.&#39;,
<a name="line296"></a>          30, goog.style.getSize(iframe).height);
<a name="line297"></a>      assertFalse(&#39;Setting min height must not cause delayed change event.&#39;,
<a name="line298"></a>          delayedChangeCalled);
<a name="line299"></a>
<a name="line300"></a>      // Test that min height doesn&#39;t shrink field.
<a name="line301"></a>      field.setMinHeight(0);
<a name="line302"></a>      clock.tick(1000);
<a name="line303"></a>      assertEquals(normalHeight, goog.style.getSize(iframe).height);
<a name="line304"></a>      assertFalse(&#39;Setting min height must not cause delayed change event.&#39;,
<a name="line305"></a>          delayedChangeCalled);
<a name="line306"></a>    } finally {
<a name="line307"></a>      goog.events.removeAll();
<a name="line308"></a>      field.dispose();
<a name="line309"></a>      clock.dispose();
<a name="line310"></a>    }
<a name="line311"></a>  }
<a name="line312"></a>}
<a name="line313"></a>
<a name="line314"></a>
<a name="line315"></a>/**
<a name="line316"></a> * @bug 1649967 This code used to throw a Javascript error.
<a name="line317"></a> */
<a name="line318"></a>function testSetMinHeightWithNoIframe() {
<a name="line319"></a>  if (goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE) {
<a name="line320"></a>    try {
<a name="line321"></a>      var field = initSeamlessField(&#39;&amp;nbsp;&#39;, {});
<a name="line322"></a>      field.makeEditable();
<a name="line323"></a>      field.setMinHeight(30);
<a name="line324"></a>    } finally {
<a name="line325"></a>      field.dispose();
<a name="line326"></a>      goog.events.removeAll();
<a name="line327"></a>    }
<a name="line328"></a>  }
<a name="line329"></a>}
<a name="line330"></a>
<a name="line331"></a>function testStartChangeEvents() {
<a name="line332"></a>  if (goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
<a name="line333"></a>    var clock = new goog.testing.MockClock(true);
<a name="line334"></a>
<a name="line335"></a>    try {
<a name="line336"></a>      var field = initSeamlessField(&#39;&amp;nbsp;&#39;, {});
<a name="line337"></a>      field.makeEditable();
<a name="line338"></a>
<a name="line339"></a>      var changeCalled = false;
<a name="line340"></a>      goog.events.listenOnce(field, goog.editor.Field.EventType.CHANGE,
<a name="line341"></a>          function() {
<a name="line342"></a>            changeCalled = true;
<a name="line343"></a>          });
<a name="line344"></a>
<a name="line345"></a>      var delayedChangeCalled = false;
<a name="line346"></a>      goog.events.listenOnce(field, goog.editor.Field.EventType.CHANGE,
<a name="line347"></a>          function() {
<a name="line348"></a>            delayedChangeCalled = true;
<a name="line349"></a>          });
<a name="line350"></a>
<a name="line351"></a>      field.stopChangeEvents(true, true);
<a name="line352"></a>      if (field.changeTimerGecko_) {
<a name="line353"></a>        field.changeTimerGecko_.start();
<a name="line354"></a>      }
<a name="line355"></a>
<a name="line356"></a>      field.startChangeEvents();
<a name="line357"></a>      clock.tick(1000);
<a name="line358"></a>
<a name="line359"></a>      assertFalse(changeCalled);
<a name="line360"></a>      assertFalse(delayedChangeCalled);
<a name="line361"></a>    } finally {
<a name="line362"></a>      clock.dispose();
<a name="line363"></a>      field.dispose();
<a name="line364"></a>    }
<a name="line365"></a>  }
<a name="line366"></a>}
<a name="line367"></a>
<a name="line368"></a>function testManipulateDom() {
<a name="line369"></a>  // Test in blended field since that is what fires change events.
<a name="line370"></a>  var editableField = initSeamlessField(&#39;&amp;nbsp;&#39;, {});
<a name="line371"></a>  var clock = new goog.testing.MockClock(true);
<a name="line372"></a>
<a name="line373"></a>  var delayedChangeCalled = 0;
<a name="line374"></a>  goog.events.listen(editableField, goog.editor.Field.EventType.DELAYEDCHANGE,
<a name="line375"></a>      function() {
<a name="line376"></a>        delayedChangeCalled++;
<a name="line377"></a>      });
<a name="line378"></a>
<a name="line379"></a>  assertFalse(editableField.isLoaded());
<a name="line380"></a>  editableField.manipulateDom(goog.nullFunction);
<a name="line381"></a>  clock.tick(1000);
<a name="line382"></a>  assertEquals(&#39;Must not fire delayed change events if field is not loaded.&#39;,
<a name="line383"></a>      0, delayedChangeCalled);
<a name="line384"></a>
<a name="line385"></a>  editableField.makeEditable();
<a name="line386"></a>  var usesIframe = editableField.usesIframe();
<a name="line387"></a>
<a name="line388"></a>  try {
<a name="line389"></a>    editableField.manipulateDom(goog.nullFunction);
<a name="line390"></a>    clock.tick(1000); // Wait for delayed change to fire.
<a name="line391"></a>    assertEquals(&#39;By default must fire a single delayed change event.&#39;,
<a name="line392"></a>        1, delayedChangeCalled);
<a name="line393"></a>
<a name="line394"></a>    editableField.manipulateDom(goog.nullFunction, true);
<a name="line395"></a>    clock.tick(1000); // Wait for delayed change to fire.
<a name="line396"></a>    assertEquals(&#39;Must prevent all delayed change events.&#39;,
<a name="line397"></a>        1, delayedChangeCalled);
<a name="line398"></a>
<a name="line399"></a>    editableField.manipulateDom(function() {
<a name="line400"></a>      this.handleChange();
<a name="line401"></a>      this.handleChange();
<a name="line402"></a>      if (this.changeTimerGecko_) {
<a name="line403"></a>        this.changeTimerGecko_.fire();
<a name="line404"></a>      }
<a name="line405"></a>
<a name="line406"></a>      this.dispatchDelayedChange_();
<a name="line407"></a>      this.delayedChangeTimer_.fire();
<a name="line408"></a>    }, false, editableField);
<a name="line409"></a>    clock.tick(1000); // Wait for delayed change to fire.
<a name="line410"></a>    assertEquals(&#39;Must ignore dispatch delayed change called within func.&#39;,
<a name="line411"></a>        2, delayedChangeCalled);
<a name="line412"></a>  } finally {
<a name="line413"></a>    // Ensure we always uninstall the mock clock and dispose of everything.
<a name="line414"></a>    editableField.dispose();
<a name="line415"></a>    clock.dispose();
<a name="line416"></a>  }
<a name="line417"></a>}
<a name="line418"></a>
<a name="line419"></a>function testAttachIframe() {
<a name="line420"></a>  var blendedField = initSeamlessField(&#39;Hi!&#39;, {});
<a name="line421"></a>  var iframe = createSeamlessIframe();
<a name="line422"></a>  try {
<a name="line423"></a>    blendedField.attachIframe(iframe);
<a name="line424"></a>  } catch (err) {
<a name="line425"></a>    fail(&#39;Error occurred while attaching iframe.&#39;);
<a name="line426"></a>  }
<a name="line427"></a>}
<a name="line428"></a>
<a name="line429"></a>
<a name="line430"></a>function createSeamlessIframe() {
<a name="line431"></a>  // NOTE(nicksantos): This is a reimplementation of
<a name="line432"></a>  // TR_EditableUtil.getIframeAttributes, but untangled for tests, and
<a name="line433"></a>  // specifically with what we need for blended mode.
<a name="line434"></a>  return goog.dom.createDom(&#39;IFRAME&#39;,
<a name="line435"></a>      { &#39;frameBorder&#39;: &#39;0&#39;, &#39;style&#39;: &#39;padding:0;&#39; });
<a name="line436"></a>}
<a name="line437"></a>
<a name="line438"></a>
<a name="line439"></a>/**
<a name="line440"></a> * Initialize a new editable field for the field id &#39;field&#39;, with the given
<a name="line441"></a> * innerHTML and styles.
<a name="line442"></a> *
<a name="line443"></a> * @param {string} innerHTML html for the field contents.
<a name="line444"></a> * @param {Object} styles Key-value pairs for styles on the field.
<a name="line445"></a> * @return {goog.editor.SeamlessField} The field.
<a name="line446"></a> */
<a name="line447"></a>function initSeamlessField(innerHTML, styles) {
<a name="line448"></a>  var field = new goog.editor.SeamlessField(&#39;field&#39;);
<a name="line449"></a>  fieldElem.innerHTML = innerHTML;
<a name="line450"></a>  goog.style.setStyle(fieldElem, styles);
<a name="line451"></a>  return field;
<a name="line452"></a>}
<a name="line453"></a>
<a name="line454"></a>
<a name="line455"></a>/**
<a name="line456"></a> * Make sure that the original field element for the given goog.editor.Field has
<a name="line457"></a> * the same size before and after attaching the given iframe. If this is not
<a name="line458"></a> * true, then the field will fidget while we&#39;re initializing the field,
<a name="line459"></a> * and that&#39;s not what we want.
<a name="line460"></a> *
<a name="line461"></a> * @param {goog.editor.Field} fieldObj The field.
<a name="line462"></a> * @param {HTMLIFrameElement} iframe The iframe.
<a name="line463"></a> */
<a name="line464"></a>function assertAttachSeamlessIframeSizesCorrectly(fieldObj, iframe) {
<a name="line465"></a>  var size = goog.style.getSize(fieldObj.getOriginalElement());
<a name="line466"></a>  fieldObj.attachIframe(iframe);
<a name="line467"></a>  var newSize = goog.style.getSize(fieldObj.getOriginalElement());
<a name="line468"></a>
<a name="line469"></a>  assertEquals(size.width, newSize.width);
<a name="line470"></a>  assertEquals(size.height, newSize.height);
<a name="line471"></a>}
</pre>


</body>
</html>
